package leetcode.editor.cn;


import java.util.*;

public class P380InsertDeleteGetrandomO1 {
    public static void main(String[] args) {
        RandomizedSet solution = new P380InsertDeleteGetrandomO1().new RandomizedSet();

    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class RandomizedSet {
        List<Integer> set;
        public RandomizedSet() {
            set = new LinkedList<>();
        }

        public boolean insert(int val) {
            if (set.contains(val)) {
                return false;
            }
            set.add(val);

            return true;
        }

        public boolean remove(int val) {
            return  set.remove(Integer.valueOf(val));
        }

        public int getRandom() {
            Random random = new Random();
            int size = set.size();
            int i = random.nextInt(size);
            return set.get(i);

        }
    }

/**
 * Your RandomizedSet object will be instantiated and called as such:
 * RandomizedSet obj = new RandomizedSet();
 * boolean param_1 = obj.insert(val);
 * boolean param_2 = obj.remove(val);
 * int param_3 = obj.getRandom();
 */
//leetcode submit region end(Prohibit modification and deletion)

}